﻿// https://mp.weixin.qq.com/s?__biz=MzUxNjY5NTYxNA==&mid=2247489941&idx=2&sn=d37ec39ffe951d192c0c881aa8bd72af&scene=21#wechat_redirect
// https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

// struct ListNode {
//     int val;
//     ListNode *next;
//     ListNode() : val(0), next(nullptr) {}
//     ListNode(int x) : val(x), next(nullptr) {}
//     ListNode(int x, ListNode *next) : val(x), next(next) {}
// };

class Solution {
public:
    string replaceSpace(string s) {
        int count = 0;
        int old_size = s.size();

        for (char c : s) {
            if (c == ' ')
                count++;
        }

        s.resize(s.size() + count * 2);
        int new_size = s.size();
        for (int i = new_size - 1, j = old_size - 1; j < i; i--, j--) {
            if (s[j] != ' ') {
                s[i] = s[j];
            } else {
                s[i] = '0';
                s[i - 1] = '2';
                s[i - 2] = '%';
                i -= 2;
            }
        }
        return s;
    }
};

int main() {
    Solution obj = Solution();
}